<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_th_ajaran extends CI_Controller {

	function __construct() {
        parent::__construct();	
		$this->load->model("master/master_th_ajaran"); 	
		$this->load->model("atur/atur_bulan"); 	
	}
	
	function index()
	{
		$data['judul'] = "Master Tahun Ajaran";
		$data['list'] = $this->master_th_ajaran->read();
		$data['main_view']='master/th_ajaran/th_ajaran';
		$this->load->view('index',$data);		
	}

	function save()
	{
		$dataInsert = array(
			'th_ajaran' => $this->input->post('th_ajaran')
		);
		$save = $this->master_th_ajaran->save($dataInsert);

		if($save){
			$id_m_th_ajaran=$this->db->insert_id();
			for($id_m_bulan=10;$id_m_bulan<=12;$id_m_bulan++){
				$dataInsert1 = array(
					'id_m_bulan' => $id_m_bulan,
					'id_m_th_ajaran' => $id_m_th_ajaran,
				);
				$this->atur_bulan->save($dataInsert1);
			}

			for($id_m_bulan=1;$id_m_bulan<=9;$id_m_bulan++){
				$dataInsert2 = array(
					'id_m_bulan' => $id_m_bulan,
					'id_m_th_ajaran' => $id_m_th_ajaran,
				);
				$this->atur_bulan->save($dataInsert2);
			}
		}
		
	}

	function edit()
	{
		$id_m_th_ajaran = $this->input->post('id_m_th_ajaran');
		$data['list']=$this->master_th_ajaran->edit($id_m_th_ajaran);	
		$this->load->view('master/th_ajaran/edit',$data);
	}
	
	function update()
	{	
		$id_m_th_ajaran=$this->input->post('id_m_th_ajaran');
		$dataUpdate=array(
			'th_ajaran'=>$this->input->post('th_ajaran')
		);
		
		$this->master_th_ajaran->update($id_m_th_ajaran,$dataUpdate);
	}
	
	function delete()
	{
		$id_m_th_ajaran = $this->input->post('id_m_th_ajaran');
		$this->master_th_ajaran->delete($id_m_th_ajaran);
	}
	
	function refresh()
	{
		$data['list'] = $this->master_th_ajaran->read();
		$this->load->view('master/th_ajaran/refresh', $data);
		
	}

	// function instant()
	// {
	// 	for($idth=1;$idth<=4;$idth++){

	// 		$id_m_th_ajaran=$idth;;
	// 		for($id_m_bulan=10;$id_m_bulan<=12;$id_m_bulan++){
	// 			$dataInsert1 = array(
	// 				'id_m_bulan' => $id_m_bulan,
	// 				'id_m_th_ajaran' => $id_m_th_ajaran,
	// 			);
	// 			$this->atur_bulan->save($dataInsert1);
	// 		}

	// 		for($id_m_bulan=1;$id_m_bulan<=9;$id_m_bulan++){
	// 			$dataInsert2 = array(
	// 				'id_m_bulan' => $id_m_bulan,
	// 				'id_m_th_ajaran' => $id_m_th_ajaran,
	// 			);
	// 			$this->atur_bulan->save($dataInsert2);
	// 		}	

	// 	}	
	// }
	
}